import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;


public class ChatQueue {
	
	class Packet
	{
		int id;
		String username;
		String msg;
		// id #s 2 - 5
		//    2: logging off
		//        2 contents:
		//            username
		//    3: poke
		//        3 contents: 
		//            username
		//    4: basic message
		//    5: whisper message
		//        4 + 5 contents: 
		//            username
		//            msg
		
		public Packet(int type, String text)
		{
			id = type;
			username = text;
		}
		
		public Packet(int type, String name, String text)
		{
			id = type;
			username = name;
			msg = text;
		}
	}
	private BlockingQueue<Packet> chatqueue;
	
	public ChatQueue() { 
		chatqueue = new ArrayBlockingQueue<Packet>(100000);
	}
	
	public boolean hasMessage() { 
		return !chatqueue.isEmpty();
	}
	
	public void add(String usr, String msg) { 
		chatqueue.add(new Packet(3,usr,msg));
	}
	
	public void add(int b, String s) { 
		chatqueue.add(new Packet(b,s));
	}
	
	public void add(int b, String usr, String msg) { 
		chatqueue.add(new Packet(b,usr,msg));
	}
	
	public Packet getMessage() { 
		return chatqueue.poll();
	}
	
	public void clearQueue() { 
		chatqueue.clear();
	}

}
